<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="age" />
<button onclick="todo()">确 定</button>
<script type="text/javascript">
    function todo() {
        var age = document.getElementById("age").value;
        if(isNaN(age)){
            alert("请输入数值。");
            return;
        }
        if(age < 10){
            alert("儿童");
        }else if(age < 20){
            alert("少年");
        }else if(age < 40){
            alert("中年")
        }else{
            alert("老年");
        }
    }

</script>
</body>
</html>